package com.sgb.goods.widget.pop;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sgb.goods.R;
import com.sgb.goods.entity.LogisticsDetailEntity;
import com.sgb.goods.utils.Constants;
import com.sgb.goods.widget.MaxHeightRecyclerView;
import com.sgb.goods.widget.pop.adapter.LogisticsDetailAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.util.DisplayUtil;

/**
 * chentao 2021/5/11
 * 订单详情弹框
 */
public class LogisticsInfoPop2 extends BasePopWindow<LogisticsDetailEntity> {

    TextView peopleName, address;
    private LogisticsDetailAdapter adapter;

    public LogisticsInfoPop2(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.goods_pop_logistics_info;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        TextView iv_close = holder.getPop().findViewById(R.id.close);
        peopleName = holder.getPop().findViewById(R.id.tv_logistics_people);
        address = holder.getPop().findViewById(R.id.tv_logistics_address);
        TextView title = holder.getPop().findViewById(R.id.title);
        title.setText("物流信息");
        MaxHeightRecyclerView maxHeightRecyclerView = holder.getPop().findViewById(R.id.recyclerView);
        iv_close.setOnClickListener(v -> this.dismiss());
        adapter = new LogisticsDetailAdapter(mContext, null);
        maxHeightRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        maxHeightRecyclerView.setAdapter(adapter);
        adapter.setOnClickListener(entity -> {
            if(entity != null){
                startReceivingDetails(entity.id);
                dismiss();
            }
        });
    }

    public void showPop(View view, LogisticsDetailEntity data) {
        peopleName.setText(data.peopleNameStr);
        address.setText(data.addressStr);
        adapter.setDatas(data.list);
        setHeight(DisplayUtil.dip2px(mContext, 450));
        this.showDownPopwindow(view, true);
    }

    /**
     * 跳转收货详情界面
     */
    private void startReceivingDetails(String id) {
        ARouter.getInstance().build(Constants.ARouter.AR_RECEIPT_GOODS_DEL)
                .withString("receiveId", id)
                .navigation();
    }

}
